package liulishuo;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

			int N = input.nextInt();
			int[] arr = new int[N];
			for(int i = 0; i < N; i++) {
				arr[i] = input.nextInt();
			}

		System.out.println(method(arr));
	}

	public static int method(int[] arr  ) {
	    int  n = arr.length;
		int sum = arr[0];
		int max = arr[0];
		for(int i = 1; i < n; i++){
			sum = getMax(sum+arr[i],arr[i]);
			if(sum >= max)
				max = sum;
		}
		
		return max;

	    }
	
	public static int getMax(int a,int b){
		return a > b ? a: b;
	}

	
}

